package com.yao_shop;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@SpringBootApplication
@EnableTransactionManagement
@EnableSwagger2
public class YaoShopApplication {

    public static void main(String[] args) {
        SpringApplication.run(YaoShopApplication.class, args);
    }
    //swagger
    @Bean
    public Docket createrestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yao_shop.controller"))
                .paths(PathSelectors.any())
                .build();
    }
    //swagger的 apiinfo
    private ApiInfo apiInfo() {
        Contact contact = new Contact("初衷.", "http://www.baidu.com/", "chuzhong1008@gmail.com");
        return new ApiInfoBuilder()
                .title("TeacherProject 中商城模块使用Swagger构建的Resinful Apis")
                .description("商城模块后台中所有的api信息！")
                .contact(contact)
                .version("v1.0.0")
                .licenseUrl("http://localhost:8080/")
                .build();
    }

}
